package crafex.resource.objects;

import crafex.engine.objects.WorldObject;
import crafex.engine.tools.FloatVertex2D;
import android.graphics.Bitmap;

public class Bullet extends WorldObject{

	public Bullet(Bitmap image, FloatVertex2D movement, FloatVertex2D startingPlace, float lifeEffects, float speed) {
		super(image);
		this.repeatedMovement = new FloatVertex2D(movement.getX(), movement.getY());
		this.coordinates = new FloatVertex2D(startingPlace.getX(), startingPlace.getY());
		this.lifeEffect = lifeEffects;
		this.speed = speed;
	}
	//TODO make the collision and update muliple time so it doesnt miss anything... or one.
	
	/**
	 * move the entity based on the movement varrable
	 */
	public void move(){
		if(repeatedMovement != null){
			movement.addToX(repeatedMovement.getX() * speed);
			movement.addToY(repeatedMovement.getY() * speed);
		}
		coordinates.addto(movement);
		if(movement.getX() != 0 && movement.getY() != 0){
			lastMovement = new FloatVertex2D(movement.getX(), movement.getY());
		}
		
		movement.reset();
	}
	
	public void update(){
		updateFirst();
		
		sprite.update(repeatedMovement);
		
		updateBeforeMove();
		
		move();
		
		
		updateLast();
	}
}
